<?php
$action=$_GET['action'];

//获得某相册的照片列表
if($action=="GetPhotoList")
{ 
   $albumId=$_POST['albumId'];
   GetPhotoList($albumId);
}

//获得照片的详细信息
if($action=="GetPhotoInfo")
{
	$photoId=$_POST['photoId'];
	GetPhotoInfo($photoId);
}

function GetPhotoList($albumId)
{
	$host="localhost";
     $user="root";
     $pwd;
     $db="phpwind1";

	//echo $host;
	//echo $albumName;
	
    $conn=mysql_connect($host,$user,$pwd) or die("Cannot connect sql");

    mysql_select_db($db) or die("Cannot select the db");
    $sql="SELECT id,name,title FROM photo where albumId=$albumId ";
	//echo $sql;
   $res= mysql_query($sql) or die("insert Album Error!".mysql_error());
   
   $photoList="[";
	
   
   $num=mysql_num_rows($res);
   
   while($row=mysql_fetch_array($res))
   {
	   $rowStr="{ id:'".$row[0]."',name:'".$row[1]."',title:'".$row[2]."'},";
	   $photoList.=$rowStr;	  
   }
   if($num>0)
   {
	   //去掉最后一个逗号
	   $photoList=substr_replace($photoList,'',-1,1);
   }
   
   $photoList.="]";
	   
  echo $photoList;
	   
}


function GetPhotoInfo($photoId)
{
	$host="localhost";
     $user="root";
     $pwd;
     $db="phpwind1";

	//echo $host;
	//echo $albumName;
	
    $conn=mysql_connect($host,$user,$pwd) or die("Cannot connect sql");

    mysql_select_db($db) or die("Cannot select the db");
    $sql="SELECT name,title,description FROM photo where id=$photoId ";
	//echo $sql;
   $res= mysql_query($sql) or die("insert Album Error!".mysql_error());
   $row=mysql_fetch_array($res);
   $photoInfo="{name:'".$row[0]."',title:'".$row[1]."',description:'".$row[2]."'}";
   
   echo $photoInfo;
}

?>